package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.core.pojo.entity.UserLoginRecord;
import com.atguigu.srb.core.service.UserLoginRecordService;
import com.atguigu.srb.result.ResponseVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户登录记录表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-04-15
 */
@Api(tags = "管理员：用户登陆日志接口")
@RestController
@RequestMapping("admin/core/userLoginRecord")
public class AdminUserLoginRecordController {
    @Autowired
    private UserLoginRecordService userLoginRecordService;

    @ApiOperation("获取用户最近的登陆日志(10条)")
    @GetMapping("/user/{userId}")
    public ResponseVo list(@PathVariable Long userId) {
        List<UserLoginRecord> list = userLoginRecordService.list(Wrappers.lambdaQuery(UserLoginRecord.class)
                .eq(UserLoginRecord::getUserId, userId)
                .orderByDesc(UserLoginRecord::getCreateTime)
                .last("limit 10"));
        return ResponseVo.ok().addData("items",list);
    }
}

